﻿/**
 * 
 * Copyright 2009, 2010 Mike Jamer [email: mikejamer@gmail.com ]
 * 
 * This File is part of Moose IRC
 * 
 * MooseIRC is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MooseIRC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MooseIRC.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using moose.irc;

namespace moose.irc.client
{
    /// <summary>
    /// Channel Form, is used to interact with a channel
    /// </summary>
    public partial class ChannelForm : Form
    {

        #region [Local Attributes]

        /// <summary>
        /// IRC Channel Binding
        /// </summary>
        private IrcChannel m_channel;

        #endregion

        #region [Construction]

        /// <summary>
        /// Initialize Channel Form
        /// </summary>
        public ChannelForm(IrcChannel channel)
        {
            InitializeComponent();
            m_channel = channel;
            configure();
            return;
        }

        /// <summary>
        /// Initial Configuration
        /// </summary>
        private void configure()
        {
            Text = m_channel.Name + "[ " + m_channel.Topic + " ]";
            update_user_list();
            return;
        }

        #endregion

        #region [Public Methods]

        /// <summary>
        /// Updates the User List for channel
        /// </summary>
        public void update_user_list()
        {
            lstUsers.Items.Clear();
            foreach (IrcUser user in m_channel.Users) {
                lstUsers.Items.Add(user.Nickname);
            }

            return;
        }

        public void write(IrcUser user, string message)
        {
            echo("[" + DateTime.Now.ToShortTimeString() + "] <" + user.Nickname + "> " + message); 
            return;
        }

        private void echo(string message)
        {

            rtxtOutput.Text += message;
            rtxtOutput.Text += Environment.NewLine;

            rtxtOutput.Select(rtxtOutput.Text.Length, 1);
            rtxtOutput.ScrollToCaret();

            txtInput.Focus();

            return;
        }

        #endregion

    }
}